package com.psa.element;

import android.content.ContentValues;
import android.database.Cursor;
import com.google.gson.Gson;
import com.psa.tool.DBTool;

/**
 *
 * @author david
 * @date 2014-05-27
 */
public class MerchandiseSeq implements IJson,ISqlObject {
    public String MerchandiseID = "";
    public int SequenceNo = -1;

    @Override
    public String toJson() {
        return new Gson().toJson(this);
    }

    @Override
    public int insert(DBTool dbTool) {
        ContentValues values = new ContentValues();
        values.put("MerchandiseID", MerchandiseID.trim());
        values.put("SequenceNo", SequenceNo);
        return (int)dbTool.insert("MerchandiseSeq", values);
    }

    @Override
    public int update(DBTool dbTool) {
        ContentValues values = new ContentValues();
        values.put("SequenceNo", SequenceNo);
        String where = "MerchandiseID = ?";
        String[] whereval = { MerchandiseID.trim() };
        return dbTool.update("MerchandiseSeq", values, where, whereval);
    }

    @Override
    public int delete(DBTool dbTool) {
        String where = "MerchandiseID = ?";
        String[] wherevalue = { MerchandiseID.trim() };
        return dbTool.delete("MerchandiseSeq", where, wherevalue);
    }

    @Override
    public ISqlObject full(Cursor cursor) {
        if (cursor!=null && cursor.moveToNext()) {
            MerchandiseSeq merchandiseSeq = new MerchandiseSeq();
            merchandiseSeq.MerchandiseID = cursor.getString(0);
            merchandiseSeq.SequenceNo = cursor.getInt(1);
            return merchandiseSeq;
        }
        return null;
    }


    @Override
    public void clear(DBTool dbTool) {
        dbTool.delete("MerchandiseSeq", "MerchandiseID Like ?", new String[]{"%"});
    }

    @Override
    public String getDataSql() {
        return "MerchandiseSeq";
    }

    @Override
    public String getSyncMethod() {
        return "getdataobjects";
    }
}
